using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Web.Script.Services;
using System.Web.Services;

using ScottCateAjax2008.Services.ProductsTableAdapters;

namespace ScottCateAjax2008.Services
{
    /// <summary>
    /// Summary description for NWProducts
    /// </summary>
    [WebService ( Namespace = "http://tempuri.org/" )]
    [WebServiceBinding ( ConformsTo = WsiProfiles.BasicProfile1_1 )]
    [ToolboxItem ( false )]
    [ScriptService]
    public class NWProducts : WebService
    {
        [WebMethod]
        public List<Product> GetProducts()
        {
            DataTable prods = null;
            using (ProductsTableAdapter adapter = new ProductsTableAdapter()) 
            {
                prods = adapter.GetData();
            }
            List<Product> prodsList = new List<Product>();
            foreach(DataRow prod in prods.Rows)
            {
                prodsList.Add(new Product(Convert.ToInt32( prod["ProductId"].ToString() ), prod["ProductName"].ToString()));
            }
            return prodsList;
        }

    }

    [Serializable]
    public class Product
    {
        private string name;
        public string Name
        {
            get { return this.name; }
            set
            {
                if ( this.name != value )
                    this.name = value;
            }
        }
        private int id;
        public int Id
        {
            get { return this.id; }
            set
            {
                if ( this.id != value )
                    this.id = value;
            }
        }

        public Product ( int id, string name )
        {
            this.name = name;
            this.id = id;
        }

        public Product()
        {}
    }
}









